home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ8801.ZIP / LETTER.ZIP / LETTER.EXP
Text File  |  1987-10-19  |  2KB  |  84 lines

  1. procedure Try(1: integer);
  2. begin
  3.    for q[1] := 0 to maxcount do begin
  4.         if fit(1) then begin
  5.              place(1);
  6.              if 1 = max then ShowResult
  7.              else try(1 + 1);
  8.              unplace(1);
  9.          end;
  10.     end;
  11. end;
  12.  
  13. { Main Program }
  14.  
  15. begin
  16.    initialize;
  17.    try(0);
  18. end.
  19.  
  20. Example 1: Eight queens problem in Pascal
  21.  
  22.  
  23.  
  24. Program test;
  25. procedure bump(n: integer);
  26. begin
  27.    writeln(n);
  28.    bump(n + 1);
  29. end
  30.  
  31. { Main Program }
  32.  
  33. begin
  34.    bump(0);
  35. end.
  36.  
  37. Example 2: Program to test levels of procedure nesting
  38.  
  39. 254 10        UNITS INCHES
  40. 254 12 *  10  UNITS FEET
  41. 254 36 *  10  UNITS YARDS
  42. 10  1         UNITS CENTIMETERS
  43. 1000  1       UNITS METERS
  44.  
  45. \ Usage:
  46. 10 FEET   . <cr>  3048  ok
  47. 3 METERS  . <cr>  3000  ok
  48. \ ........................
  49. \ etc.
  50.  
  51. Example 3: Conversion program using the defining word UNITS
  52.  
  53. VARIABLE  <AS>     0 <AS> !
  54. : AS  -1 <AS> ! ;
  55. : UNITS  CREATE  SWAP , ,  DOES>  D@  <AS> @
  56.         IF  SWAP  THEN  */  0 <AS> ! ;
  57. BEHEAD' <AS>    \ TO MAKE IT LOCAL FOR SECURITY
  58.  
  59. \ UNIT DEFINITIONS REMAIN THE SAME.
  60. \ Usage:
  61. 10 FEET . <cr>  3048  ok
  62. 3048 AS FEET .  <cr>  10 ok
  63.  
  64. Example 4: Code to convert back to input units when outputting
  65. Bytes  8088 Clocks
  66. -----  -----------------
  67.   3    12+ea = 12+9 = 21   mov     ax,word ptr {bp}.value
  68.   2     2                  mov     bx,ax
  69.   3    12+ea = 12+9 = 21   mov     ax,word ptr {bp}.value{2}
  70. -----  -----------------
  71.   8    44
  72.  
  73.   3    12+ea = 12+9 = 21   mov     ax,word ptr {bp}.value{2}
  74.   3    12+ea = 12+9 = 21   mov     bx,word ptr {bp}.value
  75. -----  -----------------
  76.   6    42
  77.  
  78.   3    24+ea = 24+9 = 33   les     bx,{bp}.value
  79.   2     2                  mov     ax,es
  80. -----  -----------------
  81.   5    35
  82.  
  83. Table 1: Timings for Example 6, page 26, July 1987 issue of DDJ
  84.